<?php
class AddEnum extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$rst ['success'] = false;
		$type = rqst ( 'type', '' );
		$enum = rqst ( 'enm' );
		if (empty ( $enum ) || empty ( $type )) {
			$rst ['msg'] = "空的枚举值或空的枚举类型";
		} else {
			$eM = new WebEnumModel ();
			$data ['enum_val'] = $enum;
			$data ['enum_type'] = $type;
			if ($eM->exist ( $data )) {
				$data ['msg'] = '枚举值已经存在';
			} else {
				$enum = $eM->insert ( $data );
				if ($enum) {
					$rst ['success'] = true;
					$rst ['id'] = $enum ['enum_id'];
				} else {
					$rst ['msg'] = '保存枚举时出错：' . $eM->last_error_msg ();
				}
			}
		}
		return new JsonView ( $rst );
	}
}